import ObsClient from 'esdk-obs-nodejs'
import {obs_config} from '../config.js'

const bucket = obs_config.bucket

const obsClient = new ObsClient({
  access_key_id: obs_config.access_key_id,
  secret_access_key: obs_config.secret_access_key,
  server: obs_config.server
})


function uploadObject(file, folder) {
  return obsClient.putObject({
    Bucket: bucket,
    Key: `${folder}/${file.split('/').slice(2).join('')}`,
    SourceFile: file
  })
}


function listFolder(folder) {
  return obsClient.listObjects({
    Bucket: bucket,
    Prefix: `${folder}/`,
  })
}

export {
  uploadObject,
  listFolder
}